#!/bin/bash
# Finder entry point for ChromaMatter Source Alpha.
# It opens the reviewed hash-locked source launcher in Terminal so first-run
# installation and self-test progress remain visible to the tester.
set -eu

CONTENTS_DIR="$(cd -- "$(dirname -- "$0")/.." && pwd -P)"
SOURCE_ROOT="$CONTENTS_DIR/Resources/ChromaMatterSource"
SOURCE_LAUNCHER="$SOURCE_ROOT/START_MACOS_SOURCE_ALPHA.command"

if [[ ! -f "$SOURCE_LAUNCHER" || -L "$SOURCE_LAUNCHER" ]]; then
    /usr/bin/logger -t ChromaMatterSourceAlpha         "Source launcher is missing or unsafe: $SOURCE_LAUNCHER"
    exit 1
fi

# Shell/CI callers receive the exact source launcher result and output. Finder
# supplies no arguments, so only a normal Finder launch opens Terminal.
if (($#)); then
    exec "$SOURCE_LAUNCHER" "$@"
fi

# Do not use sudo, alter quarantine attributes, disable Gatekeeper, or execute
# a bundled runtime here.  Terminal runs the source launcher's visible,
# hash-locked setup on this Mac.
exec /usr/bin/open -a Terminal "$SOURCE_LAUNCHER"
